package cnblogs.guzb.multikakfa;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author 顾志兵
 * @mail ipiger@163.comn
 * @since 2024-03-23
 */
@Component
@SpringBootApplication
public class MultiKafkaAppMain {

    public static void main(String[] args) {
        SpringApplication.run(MultiKafkaAppMain.class, args);
    }

    @KafkaListener(topics = "multi-kafka-topic-1", groupId = "group-1", containerFactory = "kafkaListenerContainerFactory")
    public void consumeKafka1(String message) {
        System.out.println("[KAFKA-1]: 收到消息：" + message);
    }

    @KafkaListener(topics = "multi-kafka-topic-2", groupId = "group-2", containerFactory = "kafkaListenerContainerFactory2")
    public void consumeKafka2(String message) {
        System.out.println("[KAFKA-2]: 收到消息：" + message);
    }

    @EventListener(ApplicationReadyEvent.class)
    public void init() {
        System.out.println("[MAIN]: 启动成功，等待Kakfa消息");
    }
}
